<?php

class ModulesController extends ExtendedController
{
    function __construct()
    {
        parent::__construct();
        $this->loadModel('modules');
    }

    public function index()
    {
        if(isset($_POST['submit']))
        {
            
        }
        $data = $this->models['modules']->getModuleList();
        $view = $this->loadView('index');
        $view->setBlockData($data);
        $view->setBlockData('Quản lí modules','title');
        $view->render();
    }
    
    public function install($install_type)
    {
        switch($install_type)
        {
            case 'manual':
                {

                }
                break;
        }
    }

    public function detail($id)
    {
        if(is_null($id))
        {
            Utility::redirect('modules');
            exit;
        }

        if(isset($_POST['submit']))
        {
            $this->models['modules']->handleUpdateDetail($id);
        }

        $rs = $this->models['modules']->getModule($id);
        if($rs->getSize() == 0)
        {
            Utility::error('Không tìm thấy module','modules');
            exit;
        }
        $data = $rs->getRow(0);
        $view = $this->loadView('detail');
        $view->setBlockData('Chi tiết module','title');
        $view->setBlockData($data);
        $view->render();
    }
}